@extends('layouts.app')

@section('content')
        <div class="header">
            <ul class="breadcrumb">
                <li>用户管理</li>
                <li><a href="">编辑用户</a> </li>
            </ul>
        </div>
        <div class="main-content">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#home" data-toggle="tab">编辑</a></li>
            </ul>

            <div class="rows">
                <div class="col-md-12 col-sm-12">
                    <br>
                    <div id="myTabContent" class="tab-content">
                        <div class="tab-pane active in" id="home">
                            <form id="tab" class="form-horizontal" method="post" enctype="multipart/form-data">
                                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                <div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">用户名</label>
                                    <div class="col-sm-6">
                                        {{$userinfo->email}}
                                        {{--<input type="text" class="form-control" name="email" id="email" placeholder="电子邮箱" value="{{$userinfo->email}}" required>--}}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">姓名</label>
                                    <div class="col-sm-6 col-md-6">
                                        <input type="text" class="form-control" name="name" id="name" placeholder="用户名" value="{{$userinfo->name}}" required>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="input7" class="pull-left control-label" style="width:120px;">性别</label>
                                    <div class="col-sm-6">
                                        <label class="radio-inline">
                                            <input type="radio" name="sex" value="1" @if($userinfo->sex==1) checked @endif>男
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="sex" value="0" @if($userinfo->sex==0) checked @endif>女
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">联系方式</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="phone" id="phone" placeholder="联系方式" value="{{$userinfo->phone}}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">权限组</label>
                                    <div class="col-sm-6">
                                        @if($userinfo->id==1)
                                            <span style="color: red">超级管理员</span>
                                        @else
                                            <select name="role_id" id="role_id" class="form-control" style=" width:196px;height:32px;">
                                                <option value="">请选择权限组</option>
                                                @foreach($res as $key=>$re)
                                                    <option value="{{$re->id}}" @if($userinfo->role_id==$re->id) selected @endif>{{$re->name}}</option>
                                                @endforeach
                                            </select>
                                        @endif
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">管辖区域</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" value="{{getValue($userinfo->city,'area','id','name')}}{{getValue($userinfo->area,'area','id','name')}}{{getValue($userinfo->org_id,'area','id','name')}}" disabled>
                                    </div>
                                </div>
                                {{--<div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">所属区域</label>
                                    <div class="col-sm-9">
                                        <select id="city" name="city" class="form-control" style=" width:196px;height:32px;display: inline-block;">
                                            <option value="">请选择</option>
                                            @foreach($city as $v)
                                                <option value="{{$v->id}}">{{$v->name}}</option>
                                            @endforeach
                                        </select>
                                        <select id="area" name="area" class="form-control" style=" width:196px;height:32px;display: inline-block;">
                                            <option value="">请选择</option>
                                        </select>
                                        <select id="org_id" name="org_id" class="form-control" style=" width:196px;height:32px;display: inline-block;">
                                            <option value="">请选择</option>
                                        </select>
                                    </div>
                                </div>--}}

                                {{--<div class="form-group">
                                    <label for="input1" class="pull-left control-label" style="width:120px;">警员级别</label>
                                    <div class="col-sm-6">
                                        <select name="dengji" id="dengji" class="form-control" style=" width:196px;height:32px;">
                                            <option value="">请选择级别</option>
                                            <option value="1" @if($userinfo->dengji==1) selected @endif>省级</option>
                                            <option value="2" @if($userinfo->dengji==2) selected @endif>市级</option>
                                            <option value="3" @if($userinfo->dengji==3) selected @endif>区级</option>
                                            <option value="4" @if($userinfo->dengji==4) selected @endif>派出所</option>
                                        </select>
                                    </div>
                                </div>--}}

                                <div class="btn-toolbar list-toolbar btn-toolbar2">
                                    <button class="btn btn-primary">确定</button>
                                    <a href="javascript:history.back(-1);" class="btn btn-back">返回</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <script type="text/javascript">
            $(document).on("change",'#city', function(){
                $('#area option:gt(0)').remove();
                $('#org_id option:gt(0)').remove();
                //alert(1);die;
                var cid = $("#city").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#area").append(option);
                        });
                    }
                });
            });

            $(document).on("change",'#area', function(){
                $('#org_id option:gt(0)').remove();
                var cid = $("#area").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#org_id").append(option);
                        });
                    }
                });
            });
        </script>
@stop